//引用路由组件  一级路由
// import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from "@/pages/PaySuccess"
import Center from '@/pages/Center'
// 引入二级路由组件
import MyOrder from '@/pages/Center/MyOrder'
import GroupOrder from '@/pages/Center/GroupOrder'
export default [
    // 重定向，在项目跑起来的时候，访问/，立马让他定向到首页
    {
        path: '*',
        redirect: '/home'
    },
    {
        name: 'center',
        path: '/center',
        component: Center,
        meta: { isShow: true },
        children: [
            {
                path: '/myorder',
                component: MyOrder
            },
            {
                path: '/grouporder',
                component: GroupOrder
            },
            {
                path: '/center',
                redirect: '/center/myorder'
            },

        ]



    },
    {
        name: 'paysuccess',
        path: '/paysuccess',
        component: PaySuccess,
        meta: { isShow: true }

    },
    {
        name: 'pay',
        path: '/pay',
        component: Pay,
        meta: { isShow: true },
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade') {
                next();
            } else {
                next(false);//从哪来回哪去
            }
        }

    },
    {
        name: 'trade',
        path: '/trade',
        component: Trade,
        meta: { isShow: true },
        // 独享路由守卫
        beforeEnter: (to, from, next) => {
            // 去交易页面，必须是从购物车而来
            if (from.path == '/shopcart') {
                next();
            } else {
                next(false)
            }
        }

    },
    {
        name: 'shopcart',
        path: '/shopcart',
        component: ShopCart,
        meta: { isShow: true }

    },
    {
        name: 'addcartsuccess',
        path: '/addcartsuccess',
        component: AddCartSuccess,
        meta: { isShow: true }

    },
    {
        path: '/detail/:skuId?',
        name: 'detail',
        component: Detail,
        meta: { isShow: true }

    },
    {
        path: '/home',
        component: () => import('@/pages/Home'),//懒加载  高效
        meta: { isShow: true }
    },
    {
        path: '/login',
        component: Login
    },
    {
        path: '/register',
        component: Register
    },
    {
        name: 'search',
        path: '/search/:keyWord?',
        //传递params参数一定要占位 ;加 ？表示可传或者不传params参数，当不加？时不传递params参数路时径会有问题
        component: Search,
        meta: { isShow: true },
        // 将params参数和query参数映射成属性传入路由组件
        // props: route => ({ keyword3: route.params.keyword, keyword4: route.query.keyword2 })
    },


]